package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

/**
 * @author DBX
 * @effect List集合可以存放重复的元素并且有序，提供了一套通过下标操作元素的方法
 *          实现类：ArrayList 使用数组实现，查询性能更好
 *                  LinkedList使用链表实现，增删性能好，首尾增删性能最佳
 * @date 2021/09/03/14:27
 */
public class ListDemo1 {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("2");
        list.add("3");
        list.add("4");
        list.add("6");
        list.add("7");
        list.add("8");
        list.add("9");
        list.add("0");
        list.add("11");
        System.out.println(list);
        for (String s : list) {
            System.out.print(s+" ");
        }
        System.out.println();
        Iterator<String> t = list.iterator();
        while (t.hasNext()){
            String s = t.next();
            System.out.print(s+" ");
        }
        System.out.println();
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            System.out.print(s+" ");
        }
        System.out.println();

        String  s = list.set(2,"10");
        System.out.println(s);
        System.out.println(list);

        for (int i = 0; i < list.size()/2; i++) {
            String temp = list.get(list.size()-i-1);
            list.set(list.size()-i-1,list.get(i));
            list.set(i,temp);
            list.set(i,(list.set(list.size()-i-1,list.get(i))));
        }
        System.out.println(list);
        Collections.reverse(list);
        System.out.println(list);
        Collections.shuffle(list);
        System.out.println(list);
    }
}
